package com.myres.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.myres.dao.ProductDao;
import com.myres.dao.SeriesDao;
import com.myres.model.Product;
import com.myres.model.Series;

public class SeriesService {
	private SeriesDao seriesDao;
	private ProductDao productDao;
	

	
	public ProductDao getProductDao() {
		return productDao;
	}

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	public SeriesDao getSeriesDao() {
		return seriesDao;
	}

	public void setSeriesDao(SeriesDao seriesDao) {
		this.seriesDao = seriesDao;
	}

	public Series get(int id) {
		return seriesDao.get(id);
	}

	@Transactional(readOnly = false)
	public int save(Series series) {
		return seriesDao.save(series);
	}

	@Transactional(readOnly = false)
	public int update(Series series) {
		return seriesDao.update(series);
	}

	@Transactional(readOnly = false)
	public void delete(Series series) {
		seriesDao.delete(series);
	}

	@Transactional(readOnly = false)
	public void delete(int id) {
		seriesDao.delete(id);
	}

	public List<Series> findByName(String name) {
		return seriesDao.findByName(name);
	}

	public List<Series> findAll() {
		return seriesDao.findAll();
	}

	public Series getMySeries(Product product) {
		return product.getSeries();
	}
	
	public Series getMySeries(int productId){
		Product p = productDao.get(productId);
		if(p==null)
			return null;
		return p.getSeries();
	}
}
